package com.um.swing;

//import com.apple.eawt.Application;

import com.um.swing.common.util.MessageUtil;
import com.um.swing.common.util.WindowUtil;
import com.um.swing.component.*;
import com.um.swing.dialog.JUpdateDialog;
import com.um.swing.common.inc.Config;
import com.um.swing.common.inc.Constant;
import com.um.swing.ui.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

/**
 * 名称：主窗体
 * 创建人：袁泉
 * 创建时间：2022年04月26日23:47:47
 */
public class MainView extends JFrame {
    private static final long serialVersionUID = 5417989883734105714L;
    private static MainView __instance = null;
    private JTabbedPane jTabbedPane;
    //古籍拼版Tab
    private TabGujiJoinPanel jTabGujiJoinPanel;
    private Container jContentPane = null;

    public static MainView getInstance() {
        if (__instance == null) {
            try {
                __instance = new MainView();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return __instance;
    }

    private MainView() throws Exception {
//        BeautyEyeLNFHelper.frameBorderStyle = BeautyEyeLNFHelper.FrameBorderStyle.osLookAndFeelDecorated;
//        org.jb2011.lnf.beautyeye.BeautyEyeLNFHelper.launchBeautyEyeLNF();
//        UIManager.put("RootPane.setupButtonVisible", false);
        WindowUtil.setIcon(this, null);
        setTitle(Constant.W_TITLE);
        this.setPreferredSize(Constant.W_SIZE);
        this.setSize(Constant.W_SIZE);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        jContentPane = this.getContentPane();
        jContentPane.setLayout(new BorderLayout());
        jTabbedPane = new JTabbedPane(JTabbedPane.TOP);
        jTabGujiJoinPanel = new TabGujiJoinPanel(this);
        jTabbedPane.add("古籍拼版", jTabGujiJoinPanel);
        jTabbedPane.add("碎图拼接", new JEmptyPanel());
        jTabbedPane.add("大图拆碎", new JEmptyPanel());
        jTabbedPane.add("意见反馈", new TabFeedbackPanel(this));

        jContentPane.add(jTabbedPane, BorderLayout.CENTER);
//        jTabbedPane.set
        initMenuBar();
        setLocationRelativeTo(null);

        jTabbedPane.setUI(new ITabbedPaneUI("#2e2428", "#fff"));
    }

    private void initMenuBar() {
        JMenuBar menu = new JMenuBar();            //菜单栏
        menu.setUI(new IMenuBarUI());
        JMenu file = new JMenu(Constant.W_TITLE);
        file.getPopupMenu().setUI(new IPopupMenuUI());
        file.setUI(new IMenuUI());
        JMenu about = new JMenu("关于");
        about.getPopupMenu().setUI(new IPopupMenuUI());
        about.setUI(new IMenuUI());

        JMenuItem update = new JMenuItem("软件更新");
        update.setUI(new IJMenuItemUI());
        update.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P, KeyEvent.CTRL_DOWN_MASK));
        update.addActionListener(t -> {
            JUpdateDialog.getInstance().setVisible(true);
        });

        file.add(update);


        JMenuItem exit = new JMenuItem("退出");
        exit.setUI(new IJMenuItemUI());
        exit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_W, KeyEvent.CTRL_DOWN_MASK));
        exit.addActionListener(t -> {
            int result = JOptionPane.showConfirmDialog(null, "确定退出吗？", "系统提示",
                    JOptionPane.OK_CANCEL_OPTION);
            if (result == 0)
                System.exit(0);
        });


        JSeparator sep_2 = new JSeparator();
        sep_2.setUI(new ISeparatorUI());
        file.add(sep_2);
        file.add(exit);
        menu.add(file);

        JMenuItem author = new JMenuItem("关于作者");
        author.setUI(new IJMenuItemUI());
        author.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, KeyEvent.SHIFT_DOWN_MASK));
        author.addActionListener(t -> MessageUtil.alert(null, Constant.PIC_AUTHOR_INFO, JOptionPane.INFORMATION_MESSAGE));
        JMenuItem company = new JMenuItem("关于软件");
        company.setUI(new IJMenuItemUI());
        company.addActionListener(e -> MessageUtil.alert(null, Constant.PIC_COMPANY_INFO, JOptionPane.INFORMATION_MESSAGE));

        about.add(author);
        JSeparator sep_3 = new JSeparator();
        sep_3.setUI(new ISeparatorUI());
        about.add(sep_3);
        about.add(company);
        menu.add(about);
        this.setJMenuBar(menu);
    }
}
